<?php declare(strict_types=1);
/**
 * @author      guosir
 * @copyright   2023-2025 owner
 **/

namespace Srv\Apps\Apis\Skit;

use Srv\Apps\Apis\Log\Ctl\LogCtl;
use Srv\Apps\Apis\Skit\Ctl\SkitTheaterWebCtl;
use Srv\Apps\Proto\DTO\Skit\SkitTheaterWebAddDTO;
use Srv\Apps\Proto\DTO\Skit\SkitTheaterWebDelDTO;
use Srv\Apps\Proto\DTO\Skit\SkitTheaterWebEditDTO;
use Srv\Apps\Proto\DTO\Skit\SkitTheaterWebListDTO;
use Srv\Apps\Proto\Enum\ErrCodeEnum;
use Srv\Apps\Proto\Enum\LangKeyEnum;
use Srv\Apps\Proto\Enum\Log\LogResultEnum;
use Srv\Apps\Proto\VO\Skit\SkitTheaterWebListVO;
use Srv\Libs\ConfModel\RouteConfData;
use Srv\Libs\Frame\ActionAbstract;
use Srv\Libs\Frame\DTOAbstract;
use Srv\Libs\Frame\Lang;
use Srv\Libs\Frame\Page;
use Srv\Libs\Frame\ResponseData;
use Srv\Libs\Frame\VOAbstract;

final class SkitTheaterWebAct extends ActionAbstract
{
    /**
     * @url /skit/theater/web/list
     * @auth getSkitTheaterWebList
     * @req Srv.Apps.Proto.DTO.Skit.SkitTheaterWebListDTO
     * @rsp Srv.Apps.Proto.VO.Skit.SkitTheaterWebListVO
     * 剧场Web信息列表
     */
    public function getSkitTheaterWebList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof SkitTheaterWebListDTO) || !($VOClass instanceof SkitTheaterWebListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = SkitTheaterWebCtl::tag()->getSkitTheaterWebList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass, []);
    }

    /**
     * @url /skit/theater/web/add
     * @auth skitTheaterWebAdd
     * @req Srv.Apps.Proto.DTO.Skit.SkitTheaterWebAddDTO
     * 剧场Web信息新增
     */
    public function skitTheaterWebAdd(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        unset($VOClass);
        if(!($DTOClass instanceof SkitTheaterWebAddDTO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $setData        = $RouteConfData->getParamsResData($DTOClass);
        $LogCtl         = LogCtl::tag();
        $logData        = $setData;
        $thwfId         = SkitTheaterWebCtl::tag()->skitTheaterWebAdd($setData);
        if($thwfId < 1){
            $errMsg     = '剧场Web信息新增失败';
            $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_ADD, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $errMsg         = '剧场Web信息新增成功';
        $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_ADD, LogResultEnum::LOG_RESULT_SUCCESS, $errMsg, $logData);
        return ResponseData::rspSuccAuto('', null, []);
    }

    /**
     * @url /skit/theater/web/edit
     * @auth skitTheaterWebEdit
     * @req Srv.Apps.Proto.DTO.Skit.SkitTheaterWebEditDTO
     * 剧场Web信息编辑
     */
    public function skitTheaterWebEdit(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        unset($VOClass);
        if(!($DTOClass instanceof SkitTheaterWebEditDTO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $thwfId             = intval($DTOClass->getThwfId());
        $setData            = $RouteConfData->getParamsResData($DTOClass);
        $LogCtl             = LogCtl::tag();
        $SkitTheaterWebCtl  = SkitTheaterWebCtl::tag();
        $theaterWebSrc      = $SkitTheaterWebCtl->getSkitTheaterWebSrc($thwfId);
        if(!isset($theaterWebSrc['thwf_id'])) {
            $logData        = $setData;
            $errMsg         = '剧场Web信息不存在';
            $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_EDIT, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $result             = $SkitTheaterWebCtl->skitTheaterWebEdit($thwfId, $setData);
        $logData            = ['new' => $setData, 'old' => $theaterWebSrc];
        if(!$result){
            $errMsg         = '剧场Web信息不存在';
            $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_EDIT, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $errMsg             = '剧场Web信息编辑成功';
        $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_EDIT, LogResultEnum::LOG_RESULT_SUCCESS, $errMsg, $logData);
        return ResponseData::rspSuccAuto('', null, []);
    }

    /**
     * @url /skit/theater/web/del
     * @auth skitTheaterWebDel
     * @req Srv.Apps.Proto.DTO.Skit.SkitTheaterWebDelDTO
     * 剧场Web信息删除
     */
    public function skitTheaterWebDel(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        unset($VOClass);
        if(!($DTOClass instanceof SkitTheaterWebDelDTO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $thwfId             = intval($DTOClass->getThwfId());
        $setData            = $RouteConfData->getParamsResData($DTOClass);
        $logData            = $setData;
        $LogCtl             = LogCtl::tag();
        $SkitTheaterWebCtl  = SkitTheaterWebCtl::tag();
        $theaterWebSrc      = $SkitTheaterWebCtl->getSkitTheaterWebSrc($thwfId);
        if(!isset($theaterWebSrc['thwf_id'])) {
            $errMsg         = '剧场Web信息不存在';
            $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_DEL, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $result             = $SkitTheaterWebCtl->skitTheaterWebDel($thwfId);
        if(!$result) {
            $errMsg         = '剧场Web信息删除失败';
            $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_DEL, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $errMsg             = '剧场Web信息删除成功';
        $LogCtl->logAdd(LogCtl::SKIT_THEATER_WEB_DEL, LogResultEnum::LOG_RESULT_SUCCESS, $errMsg, $logData);
        return ResponseData::rspSuccAuto('', null, []);
    }
}